#数据的读入与处理
data1<-read.csv("clin_inf.csv",sep=" ")
data2<-read.csv("count.csv",sep=" ")
data3<-read.csv("exp_inf.csv",sep=" ")
data4<-read.csv("ID_annoation.csv",sep=" ")
a1<-merge(data3,data1,by.x=1,by.y=1)
data4$gene_id<-gsub("\\.\\d+$","",data4$gene_id)
data4.1<-data4
colnames(data2)<-gsub("^X","XYA",colnames(data2))
colnames(data2)<-gsub("XYA(....)$","PTB\\1",colnames(data2))
colnames(data2)<-gsub(".$","",colnames(data2))
colnames(data2)<-gsub("gene_i","gene_id",colnames(data2))
data4.1<-data4[match(data2$gene_id,data4$gene_id),]
match(data4.1$gene_id,data2$gene_id)
counts<-column_to_rownames(a1,"样本名称")
data<-data.frame(data2)
row.names(data)<-data[,1]
data4.2.1<-data[,-1]
data<-data.frame(data4.1)
row.names(data)<-data[,1]
data4.1.1<-data[,-1]
#作图
width<-as.numeric(data4.1.1$width[1:50])
hist(width,main = "rna_seq1")
PTB008<-as.numeric(data4.2.1$PTB008[1:100])
hist(PTB008,main = "rna_seq2",breaks = 6,border = "red",col = "white")
RIN<-as.numeric(a1$RIN[1:100])
hist(RIN,main = "rna_seq3",breaks = 12,border = "blue",col = "white")

#聚类
ADdata<-read.table("ADdata2.csv",sep=",", header=FALSE)
ADdata<-data.frame(ADdata2)
ADdata3<-data.frame(ADdata2)
row.names(ADdata3)<-ADdata3[,1]
write.csv(ADdata3,"D:/R/class3/class4/ADdata3.csv")
ADdata<-read.table("ADdata2.csv",sep=",", header=TRUE)
tree<- dist(ADdata)
plot(tree)
#火山图
install.packages("ggplot2")
install.packages("gcookbook")
library(ggplot2)
load("volcano.RData")
pro<-prostat
pro$regulated <- "Not Sig"
pro$regulated[pro$P < 0.05 & pro$FC > log2(1.2)] <- "Up"
pro$regulated[pro$P < 0.05 & pro$FC < log2(1/1.2)] <- "Down"
up_down_data <- subset(pro, regulated %in% c("Up", "Down"))
pro_plot<-ggplot(pro,aes(x=FC,y=-log10(P),color=regulated))+geom_point(alpha=0.7,size=1)+scale_color_manual(values = c("Not Sig" = "gray", "Up" = "red", "Down" = "blue"))+ theme_minimal()+ labs(title = "Pro Plot", x = "Log2 Fold Change", y = "-Log10 P-value")+theme(legend.position = "top")+geom_text(data = up_down_data, aes(label = ID), hjust = 0.5, vjust = -0.5, size = 2) 
print(pro_plot)
ggsave("volcano_plot.jpg", plot = pro_plot, width = 8, height = 6, dpi = 300)
